<?php

    class TestController extends Controller
    {

        public function init(){
            parent::init();
            Yii::import('ext.simple_html_dom');

            set_time_limit(600);
            ini_set('memory_limit', '512M');
        }


        public function actionFbAPIDemo(){
            $facebook = new Facebook(array(
                'appId'  => Yii::app()->params->user['fb']['appId'],
                'secret' => Yii::app()->params->user['fb']['secret'],
            ));

            // get friends
            $friends = $facebook->api("/{$this->user->fb_id}/friends");

            // post feed
            $post_id = $facebook->api("/{$this->user->fb_id}/feed", 'POST', array(
                'link' => 'http://hehe.vn',
                'message' => "Test post to wall",
            ));

            // post image
            // return array('id' => photo_id, 'post_id' => post_id)
            $photo = $facebook->api("/{$this->user->fb_id}/photos", 'POST', array(
                'source' => "@/var/www/www.hehe.vn/public_html/files/image_images/13000/12564_original.jpg",
                'message' => "Msg",
            ));

            // tag friend to photo
            //$facebook->api("/{$photo['id']}/tags?to={$friend_id}","POST",array('owner_uid'=>$this->user->fb_id,'tag_uid'=>$friend_id,'tag_text'=>"Msg",'x'=>0,'y'=>0));

            $result = $facebook->api( array(
                'method' => 'fql.query',
                'query' => "SELECT uid,name,sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me() ORDER BY rand()) LIMIT 5",
            ));


            $likes = $facebook->api("/me/likes/342932269123960");

            echo '<pre>';print_r($likes);echo '</pre>';die;
            die('aa');
            $this->render('fb', array('facebook' => $facebook));
        }    

    }
